<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>root管理</title>
    <link href="bootstrap-4.6.1-dist/css/bootstrap.css"
          rel="stylesheet" type="text/css">
    <style>
        .dropdown{
            margin-bottom: -20px;
        }
        .dropdown:hover{
            margin: 0px;
        }
        /*.show{*/
        /*    !*display: block;*!*/
        /*    overflow: hidden;*/
        /*    visibility: hidden;*/
        /*    max-height: 0px;*/
        /*    transform: scaleY(0);*/
        /*}*/
        /*.dropdown:hover .show{*/
        /*    visibility: visible;*/
        /*    overflow: hidden;*/
        /*    transition: transform 0.2s;*/
        /*    max-height: 999999px;*/
        /*    transform: scaleY(1);*/
        /*}*/
        .userPortrait {
            width: 40px;
            height: 40px;
            border: 1px solid red;
            border-radius: 50%;
            overflow: hidden;
            margin: 0 auto;
            /*margin-top: 100px;*/
        }
        .userPortrait img {
            display: block;
            width: 100%;
            height:100%;
            border: 1px solid green;
        }
        .zt{
            text-align:center;
        }
        .btn{
            background-color:dodgerblue;
            text-align: center;
            color:white;
            width:45%;
        }
        .bt{
            background-color:dodgerblue;
            text-align: center;
            color:white;
            width:120%;
            height:39.1px;
            border-radius: 5px;
        }
    </style>
</head>
<body>

<!--眉头-->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand col-1 text-center" href="index.html">爱思教育</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse">
        <ul class="navbar-nav">
            <li class="nav-item">
                <a class="nav-link active" href="#">账户权限操作</a>
            </li>
        </ul>
    </div>
    <div class="userPortrait active dropdown">
        <a href="userInformation.html"><img src="img/defaultPortrait.jpg" alt=""></a>
    </div>
</nav>


    <!--主页面-->
    <div class="main col-10">

        <div class="row" style="margin-top:20px;">
            <div class="col-1">
            </div>
            <div class="col-10">
                <form id="form1">
                    <table>
                        <tr>
                            <font  face="隶书" size="+4" color=black style="text-align:center">用户列表</font>
                        </tr>
                        <tr>
                            <td>姓名：</td>
                            <td>
                                <input class="form-control" type="text"  name="userName" >
                            </td>
                            <td>账号：</td>
                            <td>
                                <input class="form-control" type="text"  name="userPhone" >
                            </td>
                            <td>
                                &ensp;&ensp;&ensp;&ensp;
                            </td>
                            <td>
                                <button class="bt btn-primary" id="btnRootSearch" type="button" >查询</button>

                            </td>
                        </tr>
                    </table>
                </form>
            </div>

<!--            <div class="col-5">-->
<!--                <form id="form2">-->
<!--                    <table>-->
<!--                        <tr>-->
<!--                            <font  face="隶书" size="+4" color=black style="text-align:center">普通用户列表</font>-->
<!--                        </tr>-->
<!--                        <tr>-->
<!--                            <td>姓名:</td>-->
<!--                            <td>-->
<!--                                <input type="text" name="userName">-->
<!--                            </td>-->
<!--                            <td>账号:</td>-->
<!--                            <td>-->
<!--                                <input type="text" name="userPhone">-->
<!--                            </td>-->
<!--                            <td>-->
<!--                                &ensp;&ensp;&ensp;&ensp;-->
<!--                            </td>-->
<!--                            <td>-->
<!--                                <button class="bt" type="submit" >查询</button>-->
<!--                            </td>-->
<!--                        </tr>-->
<!--                    </table>-->
<!--                </form>-->
<!--            </div>-->
            </div>
        </div>


        <div class="row" style="margin-top:40px;">
            <div class="col-1">
            </div>
            <div class="col-8">
                <table class="table table-bordered">
                    <thead class="thead-light">
                    <tr class="zt">

                        <th scope="col">#</th>
                        <th scope="col">姓名</th>
                        <th scope="col">手机号</th>
                        <th scope="col">类型</th>
                        <th scope="col">操作</th>
                    </tr>
                    </thead>
                    <tbody id="tbody">

<!--                    <tr>-->
<!--                        <th scope="row" class="zt">1</th>-->
<!--                        <td class="zt">张三</td>-->
<!--                        <td class="zt">201911050xxx</td>-->
<!--                        <td>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >解除管理员</button>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >删除账户</button>-->
<!--                        </td>-->
<!--                    </tr>-->

                    <tr>
                        <td colspan="5" class="text-center">没有数据</td>
                    </tr>
                    </tbody>
                </table>
            </div>


<!--            <div class="col-5">-->
<!--                <table class="table table-bordered">-->
<!--                    <thead class="thead-light" >-->
<!--                    <tr>-->
<!--                        <th scope="col" class="zt">#</th>-->
<!--                        <th scope="col" class="zt">姓名</th>-->
<!--                        <th scope="col" class="zt">账户</th>-->
<!--                        <th scope="col" class="zt">操作</th>-->
<!--                    </tr>-->
<!--                    </thead>-->
<!--                    <tbody>-->
<!--                    <tr>-->
<!--                        <th scope="row" class="zt">1</th>-->
<!--                        <td class="zt">李四</td>-->
<!--                        <td  class="zt">201911050xxx</td>-->
<!--                        <td>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >解除管理员</button>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >删除账户</button>-->
<!--                        </td>-->
<!--                    </tr>-->
<!--                    <tr>-->
<!--                        <th scope="row" class="zt">1</th>-->
<!--                        <td class="zt">张三</td>-->
<!--                        <td class="zt">201911050xxx</td>-->
<!--                        <td>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >解除管理员</button>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >删除账户</button>-->
<!--                        </td>-->
<!--                    </tr>-->
<!--                    <tr>-->
<!--                        <th scope="row" class="zt">1</th>-->
<!--                        <td class="zt">张三</td>-->
<!--                        <td class="zt">201911050xxx</td>-->
<!--                        <td>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >解除管理员</button>-->

<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >删除账户</button>-->
<!--                        </td>-->
<!--                    </tr>-->
<!--                    <tr>-->
<!--                        <th scope="row" class="zt">1</th>-->
<!--                        <td class="zt">张三</td>-->
<!--                        <td class="zt">201911050xxx</td>-->
<!--                        <td>-->
<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >解除管理员</button>-->

<!--                            <button class="btn btn-primary  align-content-center text-center" type="submit" >删除账户</button>-->
<!--                        </td>-->
<!--                    </tr>-->
<!--                    </tbody>-->
<!--                </table>-->
<!--            </div>-->
<!--            <div class="col-1"></div>-->
        </div>
    </div>


<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">编辑</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <form id="editform">

                    <div class="form-group row">
                        <label class="col-form-label col-2 text-center">姓名：</label>
                        <div class="col-8">
                            <input type="text" id="editUserName" name="userName" class="form-control"
                                   placeholder="真实姓名">
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-form-label col-2 text-center">手机：</label>
                        <div class="col-8">
                            <input type="text" id="editUserPhone" class="form-control" name="userPhone" placeholder="手机号">
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-form-label col-2 text-center">类型：</label>
                        <div class="col-8">
                            <input type="text" id="editUserType" class="form-control" name="userType" placeholder="验证">
                        </div>
                    </div>


                    <!-- 存放要修改数据的主键值，作为条件使用 -->
                    <input type="hidden" name="userId" id="editUserId">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="doEdit()">保存</button>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="delModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="delModalLabel">提示</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                您确定要删除用户“<span id="delUserName"></span>”吗?
                <form id="delForm">
                    <input type="hidden" name="ids" id="delUserId">
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="doDelete()">确定</button>
            </div>
        </div>
    </div>
</div>


<!--页脚-->
<div class="footer bg-primary fixed-bottom text-center">
    <p class="text-white">版权所有© Copyright 1999-2021 爱思软件股份有限公司　　中国·青岛黄岛区嘉陵江路777号 西区公寓2号   版本V-0.0.1</p>
</div>
</body>


<script src="jquery/jquery-3.6.0.min.js"></script>
<script src="bootstrap-4.6.1-dist/js/bootstrap.min.js"></script>
<script>
    jQuery(function () {
        jQuery("#btnRootSearch").click(function () {
            init();
        });
    })

</script>

<script>
    function init()
    {
        let form=jQuery("#form1").serialize();
        jQuery.post("root/root_search",form,function (rst) {
            let trs='';

            for(let i=0;i<rst.length;i++)
            {
                let u=rst[i];
                trs+=`
                        <tr>
                            <td>
                                <input type="checkbox" name="ids" value="${u.userId}">
                            </td>

                            <td>${u.userName}</td>
                            <td>${u.userPhone}</td>
                           <td>${u.userType==3?'学生':(u.userType==2?'教师':(u.userType==1?'管理员':'root'))}</td>

                            <td>
                                <a href="#" onclick='showEditDialog(${JSON.stringify(u)})'>编辑</a>
                                <a href="#" onclick='showDeleteDialog(${JSON.stringify(u)})'>删除</a>
                            </td>
                        </tr>
                    `;
            }
            if(trs.length==0)
            {
                trs=`
                         <tr>
                            <td colspan="5" class="text-center">没有数据</td>
                        </tr>
                    `;
            }
            jQuery("#tbody").html(trs);

        })
    }
    function showEditDialog(root)
    {
        jQuery("#editUserId").val(root.userId);
        jQuery("#editUserName").val(root.userName);
        jQuery("#editUserPhone").val(root.userPhone);
         jQuery("#editUserType").val(root.userType);
        jQuery("#editModal").modal("show");

    }

    function doEdit() {
        let form=jQuery("#editform").serialize();
        jQuery.post("root/edit",form,function (rst) {
            if(rst>0)
            {
                jQuery("#editModal").modal("hide");
                alert("修改成功！");
                init();
            }else{
                alert("修改失败！");
            }
        })
    }
</script>

<script>
    function showDeleteDialog(root) {
        console.log(root);
        jQuery("#delUserName").html(root.userName);
        jQuery("#delUserId").val(root.userId);
        jQuery("#delModal").modal('show');
    }
    function doDelete() {
        let form=jQuery("#delForm").serialize();
        jQuery.post("root/delete",form,function (rst) {
            if(rst>0)
            {
                alert("删除成功！");
                init();
            }else{
                alert("删除失败！");
            }
        });
        jQuery("#delModal").modal('hide');
    }
</script>


</html>


<!--http://localhost:8088/edusys/rootPower.html-->